package com.zw._02_woke_queues;

import com.rabbitmq.client.*;
import com.zw.ConnectionUtil;

import java.io.IOException;

public class Rev2 {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        //设置消费者同时处理消息数量
        channel.basicQos(1);
        DefaultConsumer consumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                try {
                    Thread.sleep(100000000L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("消费者票据:" + consumerTag);
                System.out.println("DeliveryTag:" + envelope.getDeliveryTag());
                System.out.println("交换机:" + envelope.getExchange());
                System.out.println("队列key:" + envelope.getRoutingKey());
                System.out.println("body:" + new String(body));
                channel.basicAck(envelope.getDeliveryTag(), false);
            }
        };
        channel.basicConsume(Sen.MQ_QUEUE, false, consumer);
    }
}
